import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

name= input("请输入你要搜索的内容：")
driver = webdriver.Chrome(service=Service('D:\\myproject\\feng-huang\\1.自动化\\1.selenium\\chromedriver.exe'))
driver.maximize_window()
driver.get(r'https://s.51sole.com/Search.aspx?q=%e5%86%9c%e4%b8%9a&page=2')
# 输入搜索内容
driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/input[1]').send_keys(name)
driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/input[2]').click()
count = 0
for i in range(1, 52):
    conpanys = driver.find_elements(By.XPATH, '//*[@id="main"]/div[1]/div')
    for name in conpanys:
        count += 1
        conpanys_name = name.find_element(By.XPATH, './div/div/div/div[1]/p[1]').text
        time.sleep(1)
        print(count, conpanys_name)
        if count ==24:
            break
    driver.execute_script("window.scrollBy(0,10000)")
    time.sleep(2)
    next_page = driver.find_element(By.XPATH, '//*[@id="pages"]/a[6]')
    if next_page.text == '下一页':
        next_page.click()
    else:
        driver.find_element(By.XPATH, '//*[@id="pages"]/a[8]').click()
    time.sleep(2)






time.sleep(20)